package com.yc.bran.snack.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yc.bran.snack.bean.Address;
import com.yc.bran.snack.enums.ResultEnmu;
import com.yc.bran.snack.service.IAddressService;
import com.yc.bran.snack.vo.ResultVo;

@RestController
@RequestMapping("/address")
public class AddressController {
	@Autowired 
	private IAddressService addressService;
	
	@PostMapping("/listaddr")
	public ResultVo listaddr(@RequestParam Integer uid) {
		List<Address> list = addressService.listaddr(uid);
		if(list == null || list.isEmpty()) {
			return new ResultVo(ResultEnmu.DATA_NULL);
		}
		return new ResultVo(ResultEnmu.SUCCESS, list);
	}
	
	@PostMapping("/add")
	public ResultVo add(@RequestBody Address ad) {
		int result = addressService.add(ad);
		if(result > 0) {
			return new ResultVo(ResultEnmu.SUCCESS, "成功");
		}
		return new ResultVo(ResultEnmu.DATA_NULL, "失败");
	}
}
